package top.dashuizhuyu.study.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.dashuizhuyu.study.entity.User;

/**
 * <p>
 *
 * 最基础的Shiro配置至少需要三张主表分别代表用户（user）、角色（role）、权限（permission），
 * 用户和角色，角色与权限之间都是ManyToMany的对应关系
 *
 * @author dashuizhuyu@foxmail.com
 * @date 2020/1/22 11:13
 **/
@RestController
@RequestMapping("authc")
public class AuthcController {

    @GetMapping("index")
    public Object index() {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getSession().getAttribute("user");
        return user.toString();
    }

    @GetMapping("admin")
    public Object admin() {
        return "Welcome Admin";
    }


    /** delete */
    @GetMapping("removable")
    public Object removable() {
        return "removable";
    }

    /** insert & update */
    @GetMapping("renewable")
    public Object renewable() {
        return "renewable";
    }
}
